package com.seeyou.lake.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.seeyou.lake.R

/**
 * @des
 * @author batie fancy
 * @date 2024/4/29
 */
class MyLoadingButton : FrameLayout {

    private var tvNext: TextView? = null
    private var ivLoading: ImageView? = null
    private var isShowing: Boolean = false
    private var isEnable:Boolean = true

    constructor(context: Context) : super(context) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initView()
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.layout_loading_button, null, false)
        addView(view)
        tvNext = view.findViewById<TextView>(R.id.tv_btn_next)
        ivLoading = view.findViewById(R.id.iv_btn_loading)
    }

    fun setOnMyClick(listener: (() -> Unit)?) {
        setOnClickListener {
            if (!isEnable){
                return@setOnClickListener
            }
            listener?.invoke()
        }
    }

    fun showLoading() {
        if (!isShowing) {
            ivLoading?.visibility = VISIBLE
        }
    }
    fun hideLoading() {
        ivLoading?.visibility = GONE
    }

    fun setEnable(enable:Boolean){
        this.isEnable = enable
    }


}